// 无 thgisArg 版本
Array.prototype.lMap = function (callback, thisArg) {
  if (typeof callback !== 'function') {
    throw new TypeError(`${callback} must be a function`);
  }

  const array = this;
  const resArr = new Array(array.length);

  for (let i = 0; i < array.length; i++) {
    if (array.hasOwnProperty(i)) {
      const res = callback.call(thisArg, array[i], i, array);
      resArr[i] = res;
    }
  }
  return resArr;
};
const arr0 = [1, 23, 321, 54, 564, 12];
const arr1 = arr0.lMap((item) => item - 1);
console.log(arr0);
console.log(arr1);

const calculator = {
  base: 10,
  addBase: function (numbers) {
    return numbers.lMap(function (num) {
      return num + this.base;
    }, this);
  },
};

console.log(calculator.addBase([1, 2, 3]));
